/******************** 
	作用:订单退换
	作者:蔡俊雄
	版本:V1.0
	时间:2015-09-06
********************/

$(function() {
	function changeQuantity(countElement, type) {
				var result = 1;
				var c = countElement.val();
				c = parseInt(c);
				if (isNaN(c)) {
					c = 0;
				}
				result = c;
				//
				if (type == "plus") {
					result++;
				} else {
					result--;
				}
				if (result < 1)
					result = 1;
				countElement.val(result);
				var $pTem=countElement.parent().siblings(".price-container");
				var priceItem = $pTem.find(".quantity");
				var goods_count= $pTem.find("#goods_count");
				priceItem.html(result);
				goods_count.val(result);
			}
			$("button[data-id='plus']").on("click", function() {
		try {
			var countElement = $(this).closest(".input-group").find("input[data-id='count']");
			var quantity=countElement.val();
			quantity = parseInt(quantity);
			if (isNaN(quantity)) {
				quantity = 0;
			}
			quantity++;
			var id=$(this).closest(".g-item").find("input[name='goods_ids[]']").attr("data-id");
			var url = $(this).attr("data-href");
			changeQuantity(countElement, "plus");
		} catch (e) {}
	});
	$("button[data-id='minus']").on("click", function() {
		try {
			var countElement = $(this).closest(".input-group").find("input[data-id='count']");
			var quantity=countElement.val();
			quantity = parseInt(quantity);
			if (isNaN(quantity)) {
				quantity = 0;
			}
			quantity--;
			if(quantity<1){
				General.alert("数量不能小于1");
				return;
			}
			var id=$(this).closest(".g-item").find("input[name='goods_ids[]']").attr("data-id");
			var url = $(this).attr("data-href");
			changeQuantity(countElement, "minus");
		} catch (e) {}
	});
	$("#sure").on("click", function(e) {
		var count = $("input[data-id=return]:checked").length;
		if (count <= 0) {
			General.alert("您还未勾选“退货/换货”，请勾选！", "温馨提示");
			return;
		}
		var reason = $("#reason").val();
		if(!reason){
			General.alert("您未填写退/换货原因，请填写！", "温馨提示");
			return;
		}
		var tips=$("#tpl-tips").html();
		General.confirm(tips,"您正在申请退单！",submitData);
	});
	function submitData () {
		$("#dataForm").submit();
	}
	if (General.isWeixin()) {
		try {
			$("header").hide();
		} catch (e) {

		}
	}
});